import { getApplication, getUserInfo } from 'request/api'
import { View } from '@hips/taro-ui'
import styles from './index.module.less'
import { FUNCTION_IDS } from 'tools/constant'
import UserInfo from 'components/application/user-info'
import UserMenu from 'components/application/user-menu'
import { getMenuList } from 'tools'
export default {
  name: 'Application',
  data() {
    return {
      appList: [],
      userInfo: {}
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.getUserInfo()
    },
    /**
     * 获取用户信息
     */
    async getUserInfo() {
      const res = await getUserInfo()
      this.userInfo = res
      this.getApplication(this.userInfo.currentRoleId)
    },
    /**
     * 获取菜单列表
     */
    async getApplication(currentRoleId) {
      const res = await getApplication(currentRoleId)
      // 对功能菜单分类筛选
      this.appList = getMenuList(res, FUNCTION_IDS)
    }
  },
  render() {
    return (
      <View class={styles.application}>
        <UserInfo
          userInfo={this.userInfo}
          vOn:Init={this.init}
          dataSource={this.appList}
        ></UserInfo>
        <UserMenu dataSource={this.appList}></UserMenu>
      </View>
    )
  }
}
